<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>23软件技术一班，23003009，陈赞吉，轮播图</title>
</head>
<style>

    .kuang{
        width: 750px;
        height: 400px;
        background-image: url(backgroun1.jpg);
        background-size: cover;
        transition: 0.5s;
        background-repeat: no-repeat;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        margin: 0 auto;
    }
    button{
        height: 60px;
        width: 30px;
        background-color: rgba(0, 0, 0, 0.6);
        color: aliceblue;
    }
    .foot{
        width: 750px;
        height: 50px;
        background-color: rgba(0, 0, 0, 0.4);
        position: absolute;
        bottom: 0;
        text-align: center;
    }
    li{
        display: inline-block;
        background-color: aliceblue;
        width: 10px;
        height: 10px;
        margin-left: 20px;
        margin-right: 20px;
        margin-top: 20px;
        transition: .5s;
        border-radius: 50%;

    }
    .xuanzhong{
        width: 15px;
        height: 15px;
        background-color: aqua;
    }
    
</style>
<body>          
    <div class="kuang">
        <div class="left">
            <button class="last"> < </button>
        </div>
        <div class="right">
            <button class="next"> > </button>
        </div>
           <div class="foot">
                
                    <li class="li1 xuanzhong"></li>
                    <li class="li2"></li>
                    <li class="li3"></li>
                
           </div>
    </div>
    
    <script>
        let bg = [
            { url : 'backgroun1.jpg' , title : '喜多郁代'},
            { url : 'backgroun2.jpg' , title : '图片'},
            { url : 'backgroun3.jpg' , title : '喜多2'}
        ]
        let i = 0
       
        const img = document.querySelector('.kuang')
        const last = document.querySelector('.last')
        const next = document.querySelector('.next')
        last.addEventListener('click',function(){
            i--
            if(i < 0){
            i=2
        }
            console.log(i);
            img.style.backgroundImage=`url(${bg[i].url})`
            document.querySelector('.foot .xuanzhong').classList.remove('xuanzhong')
            document.querySelector(`.foot li:nth-child(${i + 1})`).classList.add('xuanzhong')
            
        })
        
        next.addEventListener('click',function(){
            i++
            if( i > 2){
                i = 0
            }
            img.style.backgroundImage=`url(${bg[i].url})`
            document.querySelector('.foot .xuanzhong').classList.remove('xuanzhong')
            document.querySelector(`.foot li:nth-child(${i + 1})`).classList.add('xuanzhong')
        })

        function fn(){
            i++
            if(i == 3){
                i=0
                
                
            }
            else if( i==-1){
                i=3
            }
            img.style.backgroundImage=`url(${bg[i].url})`   
            document.querySelector('.foot .xuanzhong').classList.remove('xuanzhong')
            document.querySelector(`.foot li:nth-child(${i + 1})`).classList.add('xuanzhong') 
            
        }
        let lunbo = setInterval(fn,3000)

        img.addEventListener('mouseenter',function(){
            clearInterval(lunbo)
        })
        img.addEventListener('mouseleave',function(){
            lunbo = setInterval(fn,3000)
        })
        
        
        
    </script>
</body>
</html>